1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module gio.FileEnumerator; 26 27 private import gio.AsyncResultIF; 28 private import gio.Cancellable; 29 private import gio.FileIF; 30 private import gio.FileInfo; 31 private import gio.c.functions; 32 public import gio.c.types; 33 private import glib.ErrorG; 34 private import glib.GException; 35 private import glib.ListG; 36 private import gobject.ObjectG; 37 38 39 /** 40 * #GFileEnumerator allows you to operate on a set of #GFiles, 41 * returning a #GFileInfo structure for each file enumerated (e.g. 42 * g_file_enumerate_children() will return a #GFileEnumerator for each 43 * of the children within a directory). 44 * 45 * To get the next file's information from a #GFileEnumerator, use 46 * g_file_enumerator_next_file() or its asynchronous version, 47 * g_file_enumerator_next_files_async(). Note that the asynchronous 48 * version will return a list of #GFileInfos, whereas the 49 * synchronous will only return the next file in the enumerator. 50 * 51 * The ordering of returned files is unspecified for non-Unix 52 * platforms; for more information, see g_dir_read_name(). On Unix, 53 * when operating on local files, returned files will be sorted by 54 * inode number. Effectively you can assume that the ordering of 55 * returned files will be stable between successive calls (and 56 * applications) assuming the directory is unchanged. 57 * 58 * If your application needs a specific ordering, such as by name or 59 * modification time, you will have to implement that in your 60 * application code. 61 * 62 * To close a #GFileEnumerator, use g_file_enumerator_close(), or 63 * its asynchronous version, g_file_enumerator_close_async(). Once 64 * a #GFileEnumerator is closed, no further actions may be performed 65 * on it, and it should be freed with g_object_unref(). 66 */ 67 public class FileEnumerator : ObjectG 68 { 69 /** the main Gtk struct */ 70 protected GFileEnumerator* gFileEnumerator; 71 72 /** Get the main Gtk struct */ 73 public GFileEnumerator* getFileEnumeratorStruct(bool transferOwnership = false) 74 { 75 if (transferOwnership) 76 ownedRef = false; 77 return gFileEnumerator; 78 } 79 80 /** the main Gtk struct as a void* */ 81 protected override void* getStruct() 82 { 83 return cast(void*)gFileEnumerator; 84 } 85 86 /** 87 * Sets our main struct and passes it to the parent class. 88 */ 89 public this (GFileEnumerator* gFileEnumerator, bool ownedRef = false) 90 { 91 this.gFileEnumerator = gFileEnumerator; 92 super(cast(GObject*)gFileEnumerator, ownedRef); 93 } 94 95 96 /** */ 97 public static GType getType() 98 { 99 return g_file_enumerator_get_type(); 100 } 101 102 /** 103 * Releases all resources used by this enumerator, making the 104 * enumerator return %G_IO_ERROR_CLOSED on all calls. 105 * 106 * This will be automatically called when the last reference 107 * is dropped, but you might want to call this function to make 108 * sure resources are released as early as possible. 109 * 110 * Params: 111 * cancellable = optional #GCancellable object, %NULL to ignore. 112 * 113 * Returns: #TRUE on success or #FALSE on error. 114 * 115 * Throws: GException on failure. 116 */ 117 public bool close(Cancellable cancellable) 118 { 119 GError* err = null; 120 121 auto __p = g_file_enumerator_close(gFileEnumerator, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0; 122 123 if (err !is null) 124 { 125 throw new GException( new ErrorG(err) ); 126 } 127 128 return __p; 129 } 130 131 /** 132 * Asynchronously closes the file enumerator. 133 * 134 * If @cancellable is not %NULL, then the operation can be cancelled by 135 * triggering the cancellable object from another thread. If the operation 136 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned in 137 * g_file_enumerator_close_finish(). 138 * 139 * Params: 140 * ioPriority = the [I/O priority][io-priority] of the request 141 * cancellable = optional #GCancellable object, %NULL to ignore. 142 * callback = a #GAsyncReadyCallback to call when the request is satisfied 143 * userData = the data to pass to callback function 144 */ 145 public void closeAsync(int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 146 { 147 g_file_enumerator_close_async(gFileEnumerator, ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 148 } 149 150 /** 151 * Finishes closing a file enumerator, started from g_file_enumerator_close_async(). 152 * 153 * If the file enumerator was already closed when g_file_enumerator_close_async() 154 * was called, then this function will report %G_IO_ERROR_CLOSED in @error, and 155 * return %FALSE. If the file enumerator had pending operation when the close 156 * operation was started, then this function will report %G_IO_ERROR_PENDING, and 157 * return %FALSE. If @cancellable was not %NULL, then the operation may have been 158 * cancelled by triggering the cancellable object from another thread. If the operation 159 * was cancelled, the error %G_IO_ERROR_CANCELLED will be set, and %FALSE will be 160 * returned. 161 * 162 * Params: 163 * result = a #GAsyncResult. 164 * 165 * Returns: %TRUE if the close operation has finished successfully. 166 * 167 * Throws: GException on failure. 168 */ 169 public bool closeFinish(AsyncResultIF result) 170 { 171 GError* err = null; 172 173 auto __p = g_file_enumerator_close_finish(gFileEnumerator, (result is null) ? null : result.getAsyncResultStruct(), &err) != 0; 174 175 if (err !is null) 176 { 177 throw new GException( new ErrorG(err) ); 178 } 179 180 return __p; 181 } 182 183 /** 184 * Return a new #GFile which refers to the file named by @info in the source 185 * directory of @enumerator. This function is primarily intended to be used 186 * inside loops with g_file_enumerator_next_file(). 187 * 188 * To use this, %G_FILE_ATTRIBUTE_STANDARD_NAME must have been listed in the 189 * attributes list used when creating the #GFileEnumerator. 190 * 191 * This is a convenience method that's equivalent to: 192 * |[<!-- language="C" --> 193 * gchar *name = g_file_info_get_name (info); 194 * GFile *child = g_file_get_child (g_file_enumerator_get_container (enumr), 195 * name); 196 * ]| 197 * 198 * Params: 199 * info = a #GFileInfo gotten from g_file_enumerator_next_file() 200 * or the async equivalents. 201 * 202 * Returns: a #GFile for the #GFileInfo passed it. 203 * 204 * Since: 2.36 205 */ 206 public FileIF getChild(FileInfo info) 207 { 208 auto __p = g_file_enumerator_get_child(gFileEnumerator, (info is null) ? null : info.getFileInfoStruct()); 209 210 if(__p is null) 211 { 212 return null; 213 } 214 215 return ObjectG.getDObject!(FileIF)(cast(GFile*) __p, true); 216 } 217 218 /** 219 * Get the #GFile container which is being enumerated. 220 * 221 * Returns: the #GFile which is being enumerated. 222 * 223 * Since: 2.18 224 */ 225 public FileIF getContainer() 226 { 227 auto __p = g_file_enumerator_get_container(gFileEnumerator); 228 229 if(__p is null) 230 { 231 return null; 232 } 233 234 return ObjectG.getDObject!(FileIF)(cast(GFile*) __p); 235 } 236 237 /** 238 * Checks if the file enumerator has pending operations. 239 * 240 * Returns: %TRUE if the @enumerator has pending operations. 241 */ 242 public bool hasPending() 243 { 244 return g_file_enumerator_has_pending(gFileEnumerator) != 0; 245 } 246 247 /** 248 * Checks if the file enumerator has been closed. 249 * 250 * Returns: %TRUE if the @enumerator is closed. 251 */ 252 public bool isClosed() 253 { 254 return g_file_enumerator_is_closed(gFileEnumerator) != 0; 255 } 256 257 /** 258 * This is a version of g_file_enumerator_next_file() that's easier to 259 * use correctly from C programs. With g_file_enumerator_next_file(), 260 * the gboolean return value signifies "end of iteration or error", which 261 * requires allocation of a temporary #GError. 262 * 263 * In contrast, with this function, a %FALSE return from 264 * g_file_enumerator_iterate() *always* means 265 * "error". End of iteration is signaled by @out_info or @out_child being %NULL. 266 * 267 * Another crucial difference is that the references for @out_info and 268 * @out_child are owned by @direnum (they are cached as hidden 269 * properties). You must not unref them in your own code. This makes 270 * memory management significantly easier for C code in combination 271 * with loops. 272 * 273 * Finally, this function optionally allows retrieving a #GFile as 274 * well. 275 * 276 * You must specify at least one of @out_info or @out_child. 277 * 278 * The code pattern for correctly using g_file_enumerator_iterate() from C 279 * is: 280 * 281 * |[ 282 * direnum = g_file_enumerate_children (file, ...); 283 * while (TRUE) 284 * { 285 * GFileInfo *info; 286 * if (!g_file_enumerator_iterate (direnum, &info, NULL, cancellable, error)) 287 * goto out; 288 * if (!info) 289 * break; 290 * ... do stuff with "info"; do not unref it! ... 291 * } 292 * 293 * out: 294 * g_object_unref (direnum); // Note: frees the last @info 295 * ]| 296 * 297 * Params: 298 * outInfo = Output location for the next #GFileInfo, or %NULL 299 * outChild = Output location for the next #GFile, or %NULL 300 * cancellable = a #GCancellable 301 * 302 * Since: 2.44 303 * 304 * Throws: GException on failure. 305 */ 306 public bool iterate(out FileInfo outInfo, out FileIF outChild, Cancellable cancellable) 307 { 308 GFileInfo* outoutInfo = null; 309 GFile* outoutChild = null; 310 GError* err = null; 311 312 auto __p = g_file_enumerator_iterate(gFileEnumerator, &outoutInfo, &outoutChild, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0; 313 314 if (err !is null) 315 { 316 throw new GException( new ErrorG(err) ); 317 } 318 319 outInfo = ObjectG.getDObject!(FileInfo)(outoutInfo); 320 outChild = ObjectG.getDObject!(FileIF)(outoutChild); 321 322 return __p; 323 } 324 325 /** 326 * Returns information for the next file in the enumerated object. 327 * Will block until the information is available. The #GFileInfo 328 * returned from this function will contain attributes that match the 329 * attribute string that was passed when the #GFileEnumerator was created. 330 * 331 * See the documentation of #GFileEnumerator for information about the 332 * order of returned files. 333 * 334 * On error, returns %NULL and sets @error to the error. If the 335 * enumerator is at the end, %NULL will be returned and @error will 336 * be unset. 337 * 338 * Params: 339 * cancellable = optional #GCancellable object, %NULL to ignore. 340 * 341 * Returns: A #GFileInfo or %NULL on error 342 * or end of enumerator. Free the returned object with 343 * g_object_unref() when no longer needed. 344 * 345 * Throws: GException on failure. 346 */ 347 public FileInfo nextFile(Cancellable cancellable) 348 { 349 GError* err = null; 350 351 auto __p = g_file_enumerator_next_file(gFileEnumerator, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 352 353 if (err !is null) 354 { 355 throw new GException( new ErrorG(err) ); 356 } 357 358 if(__p is null) 359 { 360 return null; 361 } 362 363 return ObjectG.getDObject!(FileInfo)(cast(GFileInfo*) __p, true); 364 } 365 366 /** 367 * Request information for a number of files from the enumerator asynchronously. 368 * When all i/o for the operation is finished the @callback will be called with 369 * the requested information. 370 * 371 * See the documentation of #GFileEnumerator for information about the 372 * order of returned files. 373 * 374 * The callback can be called with less than @num_files files in case of error 375 * or at the end of the enumerator. In case of a partial error the callback will 376 * be called with any succeeding items and no error, and on the next request the 377 * error will be reported. If a request is cancelled the callback will be called 378 * with %G_IO_ERROR_CANCELLED. 379 * 380 * During an async request no other sync and async calls are allowed, and will 381 * result in %G_IO_ERROR_PENDING errors. 382 * 383 * Any outstanding i/o request with higher priority (lower numerical value) will 384 * be executed before an outstanding request with lower priority. Default 385 * priority is %G_PRIORITY_DEFAULT. 386 * 387 * Params: 388 * numFiles = the number of file info objects to request 389 * ioPriority = the [I/O priority][io-priority] of the request 390 * cancellable = optional #GCancellable object, %NULL to ignore. 391 * callback = a #GAsyncReadyCallback to call when the request is satisfied 392 * userData = the data to pass to callback function 393 */ 394 public void nextFilesAsync(int numFiles, int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 395 { 396 g_file_enumerator_next_files_async(gFileEnumerator, numFiles, ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 397 } 398 399 /** 400 * Finishes the asynchronous operation started with g_file_enumerator_next_files_async(). 401 * 402 * Params: 403 * result = a #GAsyncResult. 404 * 405 * Returns: a #GList of #GFileInfos. You must free the list with 406 * g_list_free() and unref the infos with g_object_unref() when you're 407 * done with them. 408 * 409 * Throws: GException on failure. 410 */ 411 public ListG nextFilesFinish(AsyncResultIF result) 412 { 413 GError* err = null; 414 415 auto __p = g_file_enumerator_next_files_finish(gFileEnumerator, (result is null) ? null : result.getAsyncResultStruct(), &err); 416 417 if (err !is null) 418 { 419 throw new GException( new ErrorG(err) ); 420 } 421 422 if(__p is null) 423 { 424 return null; 425 } 426 427 return new ListG(cast(GList*) __p, true); 428 } 429 430 /** 431 * Sets the file enumerator as having pending operations. 432 * 433 * Params: 434 * pending = a boolean value. 435 */ 436 public void setPending(bool pending) 437 { 438 g_file_enumerator_set_pending(gFileEnumerator, pending); 439 } 440 }